/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.webos.java.base;

import org.json.JSONObject;
import org.webos.java.root.RandomGUID;

/**
 *
 * @author kostya
 */
abstract public class Dialog<E extends Application> {
    
    private JSONObject data = new JSONObject();
    private E application = null;
    private String instanceID = null;

    public Dialog(E application) {
        this.application = application;
        instanceID = new RandomGUID().toString();
    }

    /**
     * @return the data
     */
    public JSONObject getData() {
        return data;
    }

    /**
     * @return the application
     */
    public E getApplication() {
        return application;
    }

    /**
     * @return the instanceID
     */
    public String getInstanceID() {
        return instanceID;
    }

    public void beforeClose(){
        
    }

    /**
     * @param data the data to set
     */
    public void setData(JSONObject data) {
        this.data = data;
    }

    @RemoteMessage
    public void closeDialog(JSONObject data){
        getApplication().getSession().removeDialog(this);
    }

    public void show(){
        getApplication().getSession().addDialog(this);
    }
}
